var Nenghao = function() {

	/**
	 * 绑定按钮事件
	 */
	var eventHandler = function() {
		$("#searchBtn").on("click", function() {
			var storehousecode = $("#cangfangDetail").val()
			$.ajax({
				type : "GET",
				cache : false,
				url : "nenghao/GLlist?storehousecode=" + storehousecode + "&orgcode=" + orgcode,
				success : function(responseJson) {
					if (responseJson.success == true) {// 返回true
						var data = responseJson.obj;
						if (data.length > 0) {
							console.log(data[0]);
							$("td[name=l1]").text((data[0].v1 == null ? 0 : data[0].v1) + "A");
							$("td[name=v1]").text((data[0].l1 == null ? 0 : data[0].l1) + "V");
							$("td[name=fre1]").text((data[0].fre1 == null ? 0 : data[0].fre1) + "Hz");
							$("td[name=energy1]").text((data[0].energy1 == null ? 0 : data[0].energy1) + "KWH");

							$("td[name=l2]").text((data[0].v2 == null ? 0 : data[0].v2) + "A");
							$("td[name=v2]").text((data[0].l2 == null ? 0 : data[0].l2) + "V");
							$("td[name=fre2]").text((data[0].fre2 == null ? 0 : data[0].fre2) + "Hz");
							$("td[name=energy2]").text((data[0].energy2 == null ? 0 : data[0].energy2) + "KWH");
							
							$("td[name=l3]").text((data[0].v3 == null ? 0 : data[0].v3) + "A");
							$("td[name=v3]").text((data[0].l3 == null ? 0 : data[0].l3) + "V");
							$("td[name=fre3]").text((data[0].fre3 == null ? 0 : data[0].fre3) + "Hz");
							$("td[name=energy3]").text((data[0].energy3 == null ? 0 : data[0].energy3) + "KWH");
							
							$("td[name=l_total]").text((data[0].v_total == null ? 0 : data[0].v_total) + "A");
							$("td[name=v_total]").text((data[0].l_total == null ? 0 : data[0].l_total) + "V");
							$("td[name=fre_total]").text((data[0].fre_total == null ? 0 : data[0].fre_total) + "Hz");
							$("td[name=energy_total]").text((data[0].energy_total == null ? 0 : data[0].energy_total) + "KWH");

							$("input[name=outtemp]").val(data[0].outtemp);
							$("input[name=intemp]").val(data[0].intemp + "℃");
							$("input[name=lowertemp]").val(data[0].lowertemp + "℃");
							$("input[name=avgtemp]").val(data[0].avgtemp + "℃");
							$("input[name=outhumidity]").val(data[0].outhumidity);
							$("input[name=inhumidity]").val(data[0].inhumidity + "%");
							$("input[name=hightemp]").val(data[0].hightemp + "℃");
							$("input[name=aerationtemp]").val(data[0].aerationtemp + "℃" + data[0].aerationhumidity + "%");
						}
					} else {
						QTYYComponents.bootstrapSweetAlert("", responseJson.msg, "error");
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					QTYYComponents.bootstrapSweetAlert("", "查询失败!!!", "error");
				}
			});
		});
	}

	return {
		init : function() {
			QTYYComponents.initSelect("/dict/cangfang", "cangfangDetail");
			eventHandler();
		}
	}
}();

jQuery(document).ready(function() {
	Nenghao.init();
});
